package com.itheima;

import java.util.Arrays;

public class Test03 {
    //有以下数组：
    //int[] arr = {21,22,23,24,25,26};
    //请定义方法printArray()，可以打印一个数组中偶数索引位置的元素。

    public static void main(String[] args) {
        int[] arr = {21, 22, 23, 24, 25, 26};

        int[] array = printArray(arr);

        System.out.println(arr.length);

        System.out.println(Arrays.toString(array));

    }

    public static int[] printArray(int[] arr) {
        int count = 0;

        for (int i = 0; i < arr.length; i++) {
            if (i%2==0){
                count++;
            }
        }

        int[] newarr = new int[count];

        for (int i = 0, j = 0; i < arr.length; i++) {

            if (i % 2 == 0) {
                newarr[j] = arr[i];
                j++;
            }
        }
        return newarr;
    }

}
